package com.looookme.shaozhuo.msg;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;

import java.util.ArrayList;

/**
 * Created by Shaozhuo on 2015/9/8.
 */
public class MsgList extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initView();
    }

    private void initView() {
        LinearLayout linearLayout = new LinearLayout(this);
        linearLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        linearLayout.setOrientation(LinearLayout.VERTICAL);
        setContentView(linearLayout);

        ListView mListView = new ListView(this);
        mListView.setLayoutParams(new ListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        linearLayout.addView(mListView);
        mListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, getData()));
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = new Intent();
                switch (i){
                    case 0:
                        intent.setClass(MsgList.this, Msg_Toast.class);
                        break;
                    case 1:
                        intent.setClass(MsgList.this, Msg_Notification.class);
                        break;
                    case 2:
                        intent.setClass(MsgList.this, Msg_AlertDialog.class);
                        break;
                }
                startActivity(intent);
            }
        });
    }

    public ArrayList<String> getData() {
        ArrayList<String> mData = new ArrayList<String>();
        mData.add("MSG: Toast");
        mData.add("MSG: Notification");
        mData.add("MSG: AlertDialog");

        return mData;
    }
}
